theme(text=element_text(size=15))
d <- ggplot(data=dat) + geom_point(aes(x=pctapi, y=Asian)) + geom_smooth(aes(x=pctapi, y=Asian), se=FALSE) +
geom_point(data=dat[dat$select==1,], aes(x=pctapi, y=Asian), colour="black", fill="gray", shape=21, size=3) +
xlab("Percent Asian in Voter File") + ylab("Rated Likelihood Asian") + theme_bw() + ylim(c(1.5,4.5)) +
theme(text=element_text(size=15))
#combine
pdf("Figures/figure1.pdf", width = 12, height=4)
grid.arrange(a,b,c,d, nrow=1, top=textGrob("Rated Race of Names by Actual Race Distribution", gp=gpar(fontsize=17)))
dev.off()
#clear environment
rm(list=ls())
dat <- read.csv(here("comb_traitratings.csv"))
datb <- read.csv(here("nameratings.csv"))
dat <- merge(dat, select(datb, name, race, gender, distinct))
datb <- read.csv(here("comb_traitratings_withses.csv"))
dat <- merge(dat, select(datb[datb$att=="competent",], Std..Error, name))
names <- dat %>%
filter(race=="black"&!is.na(competent)) %>%
slice_min(competent, n=3) %>%
arrange(competent) %>%
select(name) %>%
bind_rows(dat %>%
filter(race=="black"&!is.na(competent)) %>%
slice_max(competent, n=3) %>%
arrange(competent) %>%
select(name)) %>%
bind_rows(dat %>%
filter(race=="white"&!is.na(competent)) %>%
slice_min(competent, n=3) %>%
arrange(competent) %>%
select(name)) %>%
bind_rows(dat %>%
filter(race=="white"&!is.na(competent)) %>%
slice_max(competent, n=3) %>%
arrange(competent) %>%
select(name)) %>%
bind_rows(dat %>%
filter(race=="hispanic"&!is.na(competent)) %>%
slice_min(competent, n=3) %>%
arrange(competent) %>%
select(name)) %>%
bind_rows(dat %>%
filter(race=="hispanic"&!is.na(competent)) %>%
slice_max(competent, n=3) %>%
arrange(competent) %>%
select(name)) %>%
bind_rows(dat %>%
filter(race=="asian"&!is.na(competent)) %>%
slice_min(competent, n=3) %>%
arrange(competent) %>%
select(name)) %>%
bind_rows(dat %>%
filter(race=="asian"&!is.na(competent)) %>%
slice_max(competent, n=3) %>%
arrange(competent) %>%
select(name))
names <- unlist(names[[1]])
a <- dat %>%
filter(name %in% names) %>%
mutate(name = factor(name, levels=names)) %>%
arrange(competent) %>%
ggplot(aes(x=competent, y=name)) + theme_bw() +
geom_point() +
geom_errorbarh(aes(xmin=competent - 1.96*Std..Error,
xmax=competent + 1.96*Std..Error),
height=.2) +
xlim(c(2,4.3)) +
facet_wrap(~capitalize(race), nrow = 1,
scales="free") +
xlab("Competence Rating") + ylab("Name")
a
## FIGURE 3 ####
dat <- read.csv(here("mturk_nametraits_withSEs.csv"))
colnames(dat) <- c("Estimate", "Std..Error", "att", "name")
#select names and attributes for figure
names4fig <- c("Emily", "Laurie", "Latoya", "Keisha", "Octavia", "Misty")
atts4fig <- c("white", "African American", "competent", "hardworking", "intelligent", "professional", "warm", "working class")
subtable2 <- dat[(dat$name %in% names4fig)&(dat$att %in% atts4fig),]
#reformat for plot
subtable2$att <- capitalize(subtable2$att)
subtable2$att <- factor(subtable2$att, levels=rev(c("White", "white", "African American", "african american",
"Competent", "competent", "Hardworking", "hardworking",
"Intelligent", "intelligent", "Professional",
"professional", "Warm", "warm", "Working class", "working class")))
subtable2$name <- factor(subtable2$name, levels=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"))
subtable2 <- with(subtable2, subtable2[order(-as.numeric(name)),])
#select final subset for plot
white <- c("Emily", "Laurie", "Misty")
black <- c("Octavia", "Latoya", "Keisha")
#create plot
a <- ggplot() +
geom_errorbarh(data=subtable2[subtable2$name %in% white,],
aes(xmin=(Estimate-1.96*`Std..Error`),
xmax=(Estimate+1.96*`Std..Error`), y=att, fill=name),
colour="gray69", height=.5,
position=position_dodgev(height=-.5)) +
geom_errorbarh(data=subtable2[subtable2$name %in% black,],
aes(xmin=(Estimate-1.96*`Std..Error`),
xmax=(Estimate+1.96*`Std..Error`), y=att, fill=name),
colour="gray69", height=.5,
position=position_dodgev(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(x=Estimate, y=att, shape=name), size=3,
position=position_dodgev(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(x=Estimate, y=att, shape=name), size=3,
position=position_dodgev(height=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
ylab("Attribute") + xlab("Estimated Rating") +
scale_y_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class"))
a
#create plot
a <- ggplot() +
geom_errorbarh(data=subtable2[subtable2$name %in% white,],
aes(xmin=(Estimate-1.96*`Std..Error`),
xmax=(Estimate+1.96*`Std..Error`), y=att, fill=name),
colour="gray69", height=.5,
position=position_dodgev(height=-.5)) +
geom_errorbarh(data=subtable2[subtable2$name %in% black,],
aes(xmin=(Estimate-1.96*`Std..Error`),
xmax=(Estimate+1.96*`Std..Error`), y=att, fill=name),
colour="gray69", height=.5,
position=position_dodgev(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(x=Estimate, y=att, shape=name), size=3,
position=position_dodgev(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(x=Estimate, y=att, shape=name), size=3,
position=position_dodgev(height=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
ylab("Attribute") + xlab("Estimated Rating") +
scale_y_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class")) +
theme(text=element_text(size=15))
a
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodgev(height=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodgev(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodgev(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodgev(height=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_y_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class")) +
theme(text=element_text(size=15))
a
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodgev(height=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodgev(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(height=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_y_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class")) +
theme(text=element_text(size=15))
a
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodge(height=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodge(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(height=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(height=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_y_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class")) +
theme(text=element_text(size=15))
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodge(width=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", width=.5,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_y_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class")) +
theme(text=element_text(size=15))
a
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodge(width=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", width=.5,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_x_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class")) +
theme(text=element_text(size=15))
a
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodge(width=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", width=.5,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_x_discrete(breaks=rev(c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class"))) +
theme(text=element_text(size=15))
a
subtable2$att <- factor(subtable2$att, levels=(c("White", "white", "African American", "african american",
"Competent", "competent", "Hardworking", "hardworking",
"Intelligent", "intelligent", "Professional",
"professional", "Warm", "warm", "Working class", "working class")))
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodge(width=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", width=.5,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_x_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class"))) +
theme(text=element_text(size=15))
## FIGURE 3 ####
dat <- read.csv(here("mturk_nametraits_withSEs.csv"))
colnames(dat) <- c("Estimate", "Std..Error", "att", "name")
#select names and attributes for figure
names4fig <- c("Emily", "Laurie", "Latoya", "Keisha", "Octavia", "Misty")
atts4fig <- c("white", "African American", "competent", "hardworking", "intelligent", "professional", "warm", "working class")
subtable2 <- dat[(dat$name %in% names4fig)&(dat$att %in% atts4fig),]
#reformat for plot
subtable2$att <- capitalize(subtable2$att)
subtable2$att <- factor(subtable2$att, levels=(c("White", "white", "African American", "african american",
"Competent", "competent", "Hardworking", "hardworking",
"Intelligent", "intelligent", "Professional",
"professional", "Warm", "warm", "Working class", "working class")))
subtable2$name <- factor(subtable2$name, levels=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"))
subtable2 <- with(subtable2, subtable2[order(-as.numeric(name)),])
#select final subset for plot
white <- c("Emily", "Laurie", "Misty")
black <- c("Octavia", "Latoya", "Keisha")
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodge(width=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", width=.5,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_x_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class"))) +
theme(text=element_text(size=15))
#create plot
a <- ggplot() +
geom_errorbar(data=subtable2[subtable2$name %in% white,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", height=.5,
position=position_dodge(width=-.5)) +
geom_errorbar(data=subtable2[subtable2$name %in% black,],
aes(ymin=(Estimate-1.96*`Std..Error`),
ymax=(Estimate+1.96*`Std..Error`), x=att, fill=name),
colour="gray69", width=.5,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% white,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
geom_point(data=subtable2[subtable2$name %in% black,],
aes(y=Estimate, x=att, shape=name), size=3,
position=position_dodge(width=-.5)) +
theme_bw() + #ggtitle("Attribute Ratings for Black and White Women's Names") +
scale_shape_manual(values=c("Emily"=0, "Laurie"=1, "Misty"=2,
"Latoya"=15, "Keisha"=16, "Octavia"=17),
name="Name",
breaks=c("Emily", "Laurie", "Misty", "Latoya", "Keisha", "Octavia"),
labels=c("Emily"=expression(bold(Emily)),
"Laurie"=expression(bold(Laurie)),
"Latoya"=expression(bold(Latoya)),
"Keisha"=expression(bold(Keisha)))) +
xlab("Attribute") + ylab("Estimated Rating") +
scale_x_discrete(breaks=c("White", "African American", "Competent", "Hardworking",
"Intelligent", "Professional", "Warm", "Working class")) +
theme(text=element_text(size=15))
a
pdf("Figures/figure3.pdf", width=12, height=4)
a
dev.off()
## FIGURE 4 ####
dat <- read.csv(here("experiment_rawdata.csv"))
summarize <- dplyr::summarize
#create summary table of all allocations
a <- dat %>% group_by(tc) %>% summarize(mean(oppbucks, na.rm=T))
b <- dat %>% group_by(tc) %>% summarize(mean(embucks, na.rm=T))
c <- dat %>% group_by(tc) %>% summarize(mean(stbucks, na.rm=T))
d <- dat %>% group_by(tc) %>% summarize(sd(embucks, na.rm=T)/sqrt(n()))
f <- dat %>% group_by(tc) %>% summarize(sd(oppbucks, na.rm=T)/sqrt(n()))
g <- dat %>% group_by(tc) %>% summarize(sd(stbucks, na.rm=T)/sqrt(n()))
h <- dat %>% group_by(tc) %>% summarize(length(stbucks))
tab1 <- cbind(b[,2], a[,2], c[,2], d[,2], f[,2], g[,2], h[,2])
colnames(tab1) <- c("Emily $", "Other $", "State $", "SD Em", "SD Opp", "SD St", "N")
rownames(tab1) <- c("Excellent Keisha", "Excellent Laurie", "Excellent Misty",
"Excellent Octavia", "Poor Keisha", "Poor Laurie", "Poor Misty", "Poor Octavia")
#restructure to long for plotting purposes
a <- cbind(tab1$`Emily $`, tab1$`SD Em`, tab1$N, rownames(tab1), rep("em", 8))
a <- rbind(a, cbind(tab1$`Other $`, tab1$`SD Opp`, tab1$N, rownames(tab1), rep("op", 8)))
a <- rbind(a, cbind(tab1$`State $`, tab1$`SD St`, tab1$N, rownames(tab1), rep("st", 8)))
tab4 <- data.frame(a)
colnames(tab4) <- c("bucks", "sd", "n", "condition", "recipient")
tab4$bucks <- as.numeric(as.character(tab4$bucks))
tab4$sd <- as.numeric(as.character(tab4$sd))
tab4$n <- as.numeric(as.character(tab4$n))
tab4$recipient <- relevel(factor(tab4$recipient), ref="op")
#create subsets for plotting
pooronly <- c("Poor Keisha", "Poor Laurie", "Poor Misty", "Poor Octavia")
exonly <- c("Excellent Keisha", "Excellent Laurie", "Excellent Misty", "Excellent Octavia")
#change labels and orders
tab4$recipient <- factor(tab4$recipient, levels = c("em", "op", "st"))
tab4$condition <- factor(tab4$condition, levels= c("Excellent Keisha", "Excellent Laurie", "Excellent Misty",
"Excellent Octavia", "Poor Laurie","Poor Octavia", "Poor Keisha", "Poor Misty"))
ggplot(data=tab4[tab4$condition %in% pooronly,]) + geom_bar(aes(x="op", y=bucks, fill=recipient), stat="identity", position="dodge", colour="black", width=3) +
theme_bw() + facet_wrap(~condition, nrow=1) +
xlab("") +
theme(axis.text.x=element_blank(), axis.ticks.x=element_blank()) + ylab("Average Dollars Allocated") +
scale_fill_manual(name="Recipient", labels=c("Excellent Emily", "Treatment Name", "State"), values=c("grey38", "grey69", "gray100")) +
geom_errorbar(aes(x=recipient, ymin=bucks-(1.96*(sd)), ymax=bucks+(1.96*(sd))), position="dodge", width=.5) +
theme(text=element_text(size=15))
#create plot
pdf(here("Figures/figure4.pdf"), width=15, height=4)
ggplot(data=tab4[tab4$condition %in% pooronly,]) + geom_bar(aes(x="op", y=bucks, fill=recipient), stat="identity", position="dodge", colour="black", width=3) +
theme_bw() + facet_wrap(~condition, nrow=1) +
xlab("") +
theme(axis.text.x=element_blank(), axis.ticks.x=element_blank()) + ylab("Average Dollars Allocated") +
scale_fill_manual(name="Recipient", labels=c("Excellent Emily", "Treatment Name", "State"), values=c("grey38", "grey69", "gray100")) +
geom_errorbar(aes(x=recipient, ymin=bucks-(1.96*(sd)), ymax=bucks+(1.96*(sd))), position="dodge", width=.5) +
theme(text=element_text(size=15))
dev.off()
convert.g(path="../Replication Code/Figures", from="pdf", to="eps", options=c("-density 300"))
